package com.qf.business.course.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.business.course.dao.UserBuyRecoredDao;
import com.qf.commons.core.exception.ServiceException;
import com.qf.data.course.entity.UserBuyRecored;
import com.qf.business.course.service.UserBuyRecoredService;
import org.springframework.stereotype.Service;

/**
 * 购买记录表(UserBuyRecored)表服务实现类
 *
 * @author makejava
 * @since 2022-10-14 17:18:38
 */
@Service("userBuyRecoredService")
public class UserBuyRecoredServiceImpl extends ServiceImpl<UserBuyRecoredDao, UserBuyRecored> implements UserBuyRecoredService {

    @Override
    public boolean save(UserBuyRecored entity) {

        //查询一次
        long count = this.query().eq("uid", entity.getUid()).eq("cid", entity.getCid()).count();
        if (count > 0)
            throw new ServiceException(500, "不能重复购买课程！");

        return super.save(entity);
    }
}

